﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace CLFramework.IO
{
    public static class FileOperationHelper
    {
        public static string ReadToEnd(string path)
        {
            FileStream fin;
            if (!File.Exists(path)) fin = File.Create(path);
            else fin = new FileStream(path, FileMode.Open, FileAccess.Read);
            StreamReader brin = new StreamReader(fin, Encoding.Default);
            string s = brin.ReadToEnd(); brin.Close(); return s;
        }

        public static string ReadFirstLine(string path)
        {
            FileStream fin;
            if (!File.Exists(path)) fin = File.Create(path);
            else fin = new FileStream(path, FileMode.Open, FileAccess.Read);
            StreamReader brin = new StreamReader(fin, Encoding.Default);
            string s = brin.ReadLine(); brin.Close(); return s;
        }

        public static void Save(string s, string path)
        {
            FileStream fout = new FileStream(path, FileMode.Create, FileAccess.Write);
            StreamWriter brout = new StreamWriter(fout, Encoding.Default);
            brout.Write(s);
            brout.Close();
        }
    }
}
